package com.lib.base.utils

import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders

object ViewModelUtils {
    inline fun <reified T : ViewModel> getModel(fragment: Fragment, c: T): T {
        return ViewModelProviders.of(fragment, object : ViewModelProvider.Factory {
            override fun <T : ViewModel?> create(modelClass: Class<T>): T {
                return c as T
            }
        })[T::class.java]
    }

    inline fun <reified T : ViewModel> getModel(activity: AppCompatActivity, c: Class<T>): T {
        return ViewModelProviders.of(activity)[c]
    }

}